package com.ruoyi.web.controller.mes;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.domain.vo.MaterialRejectVo;
import com.ruoyi.web.domain.vo.MaterialReturnVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.mes.MesMaterialReject;
import com.ruoyi.web.service.IMesMaterialRejectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物料退货Controller
 * 
 * @author levicash
 * @date 2024-01-30
 */
@RestController
@RequestMapping("/mes/materialreject")
public class MesMaterialRejectController extends BaseController
{
    @Autowired
    private IMesMaterialRejectService mesMaterialRejectService;

    /**
     * 查询物料退货列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MesMaterialReject mesMaterialReject)
    {
        startPage();
        List<MesMaterialReject> list = mesMaterialRejectService.selectMesMaterialRejectList(mesMaterialReject);
        return getDataTable(list);
    }

    /**
     * 导出物料退货列表
     */
    @Log(title = "物料退货", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesMaterialReject mesMaterialReject)
    {
        List<MesMaterialReject> list = mesMaterialRejectService.selectMesMaterialRejectList(mesMaterialReject);
        ExcelUtil<MesMaterialReject> util = new ExcelUtil<MesMaterialReject>(MesMaterialReject.class);
        util.exportExcel(response, list, "物料退货数据");
    }

    /**
     * 获取物料退货详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mesMaterialRejectService.selectMesMaterialRejectById(id));
    }

    /**
     * 新增物料退货
     */
    @Log(title = "物料退货", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesMaterialReject mesMaterialReject)
    {
        return toAjax(mesMaterialRejectService.insertMesMaterialReject(mesMaterialReject));
    }

    /**
     * 修改物料退货
     */
    @Log(title = "物料退货", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesMaterialReject mesMaterialReject)
    {
        return toAjax(mesMaterialRejectService.updateMesMaterialReject(mesMaterialReject));
    }

    /**
     * 删除物料退货
     */
    @Log(title = "物料退货", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mesMaterialRejectService.deleteMesMaterialRejectByIds(ids));
    }

    /**
     * 查询物料退货明细列表
     */
    @GetMapping("/detail")
    public TableDataInfo detail(MaterialRejectVo materialRejectVo) {
        startPage();
        Map<String, Object> map = new HashMap<>();
        map.put("rejectCode", materialRejectVo.getRejectCode());
        map.put("supplierCode", materialRejectVo.getSupplierCode());
        map.put("materialCode", materialRejectVo.getMaterialCode());
        map.put("materialName", materialRejectVo.getMaterialName());
        map.put("beginTime", materialRejectVo.getBeginTime());
        map.put("endTime", materialRejectVo.getEndTime());
        map.put("status", materialRejectVo.getStatus());
        List<MaterialRejectVo> list = mesMaterialRejectService.selectMesMaterialRejectDetailList(map);
        return getDataTable(list);
    }
}
